/*
 * button类型type:1查看详情、2编辑、3发送、4取消发送、5重新发送,
 * status状态:1.未发送/保存 2.已发送 3.发送中 4.发送失败 5.已取消,
 * sendFlag时效类型：1.实时 2.定时
 */
function setButton(type, status, sendFlag) {
  if (status == '2' || status == '3') {
    if (type == 1) {
      return 'inline-block'
    } else {
      return 'none'
    }
  }
  if (status == '4') {
    if (type == 1 || type == 2 || type == 5) {
      return 'inline-block'
    } else {
      return 'none'
    }
  }
  if (status == '1') {
    if (sendFlag == 1) {
      if (type == 1 || type == 2 || type == 3 || type == 4) {
        return 'inline-block'
      } else {
        return 'none'
      }
    } else {
      if (type == 1 || type == 2 || type == 4) {
        return 'inline-block'
      } else {
        return 'none'
      }
    }
  }
  if (status == '5') {
    if (type == 1) {
      return 'inline-block'
    } else {
      return 'none'
    }
  }

}

function ColumnsLog(_this) {
  let vm = _this
  let ColumnsLog = [{
      key: 'msgTitle',
      title: '消息标题',
      minwidth: 140,
      align: 'center',
      render: (h, params) => {
        return h('div', params.row.msgTitle ? params.row.msgTitle : '-')
      }
    },
    {
      key: 'sendCompany',
      title: '接收公司',
      minwidth: 140,
      align: 'center',
      // render: (h, params) => {
      //   return h('div', {
      //       style: {
      //         height: '48px',
      //         overflow: 'hidden',
      //         whiteSpace: 'nowrap',
      //         textOverflow: 'ellipsis',
      //         lineHeight: '48px'
      //       }
      //     },
      //     h(
      //       'Poptip', {
      //         props: {
      //           placement: 'right',
      //           transfer: true,
      //           width: '380',
      //           trigger: 'hover',
      //           popperClass: 'N_poptip',
      //         },
      //       },
      //       [
      //         h(
      //           'span', {
      //             class: 'featureZ'
      //           },
      //           params.row.sendCompanyAnduserNam
      //         ),

      //         h(
      //           'div', {
      //             slot: 'content',
      //           },
      //           params.row.sendCompanyAnduserNam
      //         ),
      //       ]
      //     ),
      //     params.row.sendCompanyAnduserName)
      // }
      render(h, params) {
        return h(
          'div', {
            props: {
              // disabled:params.row.buildingId?false:true,
              type: 'text',
            },
            style: {
              cursor: 'pointer',
              height: '48px',
              overflow: 'hidden',
              whiteSpace: 'nowrap',
              textOverflow: 'ellipsis',
              lineHeight: '48px'
            },

          },
          [
            params.row.sendCompanyAnduserName ?
            h(
              'Poptip', {
                props: {
                  placement: 'right',
                  transfer: true,
                  width: '380',
                  trigger: 'hover',
                  popperClass: 'N_poptip',
                },
              },
              [
                h(
                  'div', {
                    class: 'featureZ'
                  },
                  params.row.sendCompanyAnduserName
                ),

                h(
                  'div', {
                    slot: 'content',
                  },
                  params.row.sendCompanyAnduserName
                ),
              ]
            ) :
            h('div', params.row.sendCompanyAnduserName),
          ],
          h('div', params.row.sendCompanyAnduserName),
        )
      },
    },
    {
      key: 'peopleAll',
      title: '总人数/已阅/未阅',
      minwidth: 140,
      align: 'center',

      render: (h, params) => {
        return h('div', {
          style: {
            color: '#3366ff',
            cursor: 'pointer',
          },
          on: {
            click: (e) => {
              vm.handelReadDetail(params.row)
            },
          },
        }, params.row.peopleAll)
      }
    },
    {
      key: 'userName',
      title: '创建人',
      minwidth: 140,
      align: 'center',
      render: (h, params) => {
        return h('div', params.row.userName ? params.row.userName : '-')
      }
    },
    {
      key: 'sendTime',
      title: '发送时间',
      minwidth: 140,
      align: 'center',
      render: (h, params) => {
        return h('div', params.row.sendTime ? params.row.sendTime : '-')
      }
    },
    {
      key: 'createTime',
      title: '创建时间',
      minwidth: 140,
      align: 'center',
      render: (h, params) => {
        return h('div', params.row.createTime ? params.row.createTime : '-')
      }
    },
    {
      key: 'sendFlagTxt',
      title: '时效',
      minwidth: 80,
      align: 'center',
      render: (h, params) => {
        return h('div', params.row.sendFlagTxt ? params.row.sendFlagTxt : '-')
      }
    },
    {
      key: 'saveState',
      title: '发送状态',
      minwidth: 60,
      align: 'center',
      render: (h, params) => {
        return h('div', vm.$formatter.switchName('msgType', params.row.saveState))
      }
    },
    {
      key: 'handles',
      title: '操作',
      width: 280,
      align: 'center',
      render: (h, params) => {
        return h('div', [
          h('span', {
            style: {
              color: '#3366ff',
              display: setButton(1, params.row.saveState, params.row.sendFlag),
              cursor: 'pointer',
              padding: '0 3px'
            },
            on: {
              click: (e) => {
                vm.handelBtn(params.row, 1)
              },
            },
          }, '查看详情'),
          h('span', {
            style: {
              color: '#3366ff',
              display: setButton(2, params.row.saveState, params.row.sendFlag),
              cursor: 'pointer',
              padding: '0 3px'
            },
            on: {
              click: (e) => {
                vm.handelBtn(params.row, 2)
              },
            },
          }, '编辑'),
          h('span', {
            style: {
              color: '#3366ff',
              display: setButton(3, params.row.saveState, params.row.sendFlag),
              cursor: 'pointer',
              padding: '0 3px'
            },
            on: {
              click: (e) => {
                vm.handelBtn(params.row, 3)
              },
            },
          }, '发送'),
          h('span', {
            style: {
              color: '#3366ff',
              display: setButton(4, params.row.saveState, params.row.sendFlag),
              cursor: 'pointer',
              padding: '0 3px'
            },
            on: {
              click: (e) => {
                vm.handelBtn(params.row, 4)
              },
            },
          }, '取消发送'),
          h('span', {
            style: {
              color: '#3366ff',
              display: setButton(5, params.row.saveState, params.row.sendFlag),
              cursor: 'pointer',
              padding: '0 3px'
            },
            on: {
              click: (e) => {
                vm.handelBtn(params.row, 5)
              },
            },
          }, '重新发送'),

        ])
      }
    },
  ]
  return ColumnsLog
}

function readDetailColumns(_this) {
  let vm = _this
  let columns = [{
    key: 'orgName',
    title: '分公司',
    minwidth: 180,
    align: 'center',
    render: (h, params) => {
      return h('div', params.row.orgName ? `${params.row.orgName}` : '-')
    }
  }, {
    key: 'buildingName',
    title: '案场',
    minwidth: 180,
    align: 'center',
    render: (h, params) => {
      return h('div', params.row.buildingName ? `${params.row.buildingName}` : '-')
    }
  }, {
    key: 'totalPeople',
    title: '总人数',
    minwidth: 140,
    align: 'center',
    render: (h, params) => {
      return h('div', params.row.totalPeople ? `${params.row.totalPeople}` : '-')
    }
  }, {
    key: 'readPeople',
    title: '已阅',
    minwidth: 140,
    align: 'center',
    render: (h, params) => {
      return h('div', params.row.readPeople ? `${params.row.readPeople}` : '-')
    }
  }, {
    key: 'unreadPeople',
    title: '未阅',
    minwidth: 140,
    align: 'center',
    render: (h, params) => {
      return h('div', params.row.unreadPeople ? `${params.row.unreadPeople}` : '-')
    }
  }]
  return columns
}
export default {
  ColumnsLog,
  readDetailColumns
}